<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/7/7
 * Time: 13:57
 */
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;

class GoodsController extends Controller{
      //获取产品列表
      public function get_goods_list(){
        $goods = Db::table('goods')
                ->alias('g')
                ->join('goods_type gt','g.type_id=gt.id')
                ->field('g.*,gt.name type_name')
                ->select();
        if($goods){
            return json(['code'=>0,'msg'=>'ok','result'=>['data'=>$goods]]);
        }else{
            return json(['code'=>1,'msg'=>'产品不存在','result'=>[]]);
        }

      }
      //产品详情
     public function view_goods(){
         $id = Request::instance()->param('id');
         $goods = Db::table('goods')
             ->alias('g')
             ->join('goods_type gt','g.type_id=gt.id')
             ->field('g.*,gt.name type_name')
             ->where('g.id',$id)
             ->find();
         if($goods){
             return json(['code'=>0,'msg'=>'ok','result'=>['data'=>$goods]]);
         }else{
             return json(['code'=>1,'msg'=>'产品不存在','result'=>[]]);
         }
     }
     //

}